﻿Imports kplusLogic
Imports kplusLogic.KPLUS.Logic
Imports kplusEntity.KPLUS.Entity
Imports System.Globalization

Partial Public Class frmCategoriaPonderadorBnd
    Inherits System.Web.UI.Page
    Private strConexion As String
    Private strPeriodo As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            CargarPeriodo()
            CargarTipoExposicion()
            CargarGvwHistorico()
        End If
    End Sub
    Private Sub CargarPeriodo()
        For i = 0 To 11 Step 1
            ddlMes.Items.Add(CultureInfo.CurrentCulture.DateTimeFormat.MonthNames(i))
        Next
        For i = 0 To 9 Step 1
            ddlAnhio.Items.Add(Convert.ToInt32(DateAndTime.Now.Year) - i)
        Next
    End Sub
    Public Function ObtenerPeriodoSeleccionado() As String
        Dim strMes As String
        Dim strAnhio As String

        If (ddlMes.SelectedIndex) <= 9 Then
            strMes = "0" + (ddlMes.SelectedIndex + 1).ToString
        Else
            strMes = (ddlMes.SelectedIndex + 1).ToString
        End If

        strAnhio = ddlAnhio.Items.Item(ddlAnhio.SelectedIndex).ToString
        strPeriodo = strAnhio + strMes
        Return strPeriodo
    End Function
    Private Sub CargarGvwHistorico()
        Dim objLTipoExposicion As New LTipoExposicion
        Dim strPeriodo As String = ObtenerPeriodoSeleccionado()
        Dim intVersion As Integer = 1
        Dim lstTipoExposicion As New List(Of ETipoExposicion)
        strConexion = ConfigurationManager.ConnectionStrings("ConnectionStringOracle").ConnectionString

        lstTipoExposicion = objLTipoExposicion.fListarTipoExposicion(strConexion, strPeriodo, intVersion)
        If lstTipoExposicion.Count > 0 Then
            gvwHistorial.Visible = True
            gvwHistorial.DataSource = lstTipoExposicion
            gvwHistorial.DataBind()
        Else
            gvwHistorial.Visible = False
        End If

    End Sub
    Private Sub CargarTipoExposicion()
        Dim objLTipoExposicion As New LTipoExposicion
        Dim objETipoExposicion As New EBaseParametro
        Dim intVersion As Integer = 1

        Dim strPeriodoMes As String = Request.QueryString("strPeriodoMes")
        Dim strPeriodoAnhio As String = Request.QueryString("strPeriodoAnhio")
        Dim strVersion As String = Request.QueryString("strVersion")

        IIf(String.IsNullOrEmpty(strPeriodoMes), ddlMes.Items(0).Selected = True, ddlMes.SelectedValue = strPeriodoMes)
        IIf(String.IsNullOrEmpty(strPeriodoAnhio), ddlAnhio.Items(0).Selected = True, ddlAnhio.SelectedValue = strPeriodoAnhio)
        'IIf(String.IsNullOrEmpty(strVersion), ddlVersion.Items(0).Selected = True, ddlAnhio.SelectedValue = strVersion)
        'IIf(String.IsNullOrEmpty(strVersion), intVersion = 1, intVersion = Convert.ToInt32(strVersion))

        strConexion = ConfigurationManager.ConnectionStrings("ConnectionStringOracle").ConnectionString
        'objETipoExposicion = objLTipoExposicion.fObtenerTipoExposicion(strConexion, strPeriodo, intVersion)

        With objETipoExposicion
            lblFechaRegistro.Text = .FecRegistro
            lblUsuario.Text = .CodUsrRegistro
            txtDetalle.Text = .TipoOperacion
        End With

    End Sub
    Protected Sub ddlMes_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlMes.SelectedIndexChanged
        CargarGvwHistorico()
    End Sub

    Protected Sub ddlAnhio_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAnhio.SelectedIndexChanged
        CargarGvwHistorico()
    End Sub
End Class